import type { IPageData } from "~/types/common";
import type { IDepartment, IUserEmployee } from "~/types/manage/system/user";
import { request } from "~/utils/http";

export const apiDepartmentsList = (): Promise<IDepartment[]> =>
  request.get("/departments/list");

export const apiDepartmentsTree = (): Promise<IDepartment[]> =>
  request.get("/departments/tree");

export const apiDepartmentsUsers = (
  departmentId: number,
  params: {
    pageNum: number;
    pageSize: number;
    name?: string;
  },
): Promise<IPageData<IUserEmployee>> =>
  request.get(`/departments/${departmentId}/users`, {
    params,
  });

export const apiAddDepartment = (data: Partial<IDepartment>) =>
  request.post("/departments", data);

export const apiModifyDepartment = (id: number, data: Partial<IDepartment>) =>
  request.put(`/departments/${id}`, data);

export const apiModifyDepartmentUser = (
  id: number,
  data: Partial<IUserEmployee>,
) => request.put(`/departments/${id}/users/`, data);
